#ifndef SPRITE_H
#define SPRITE_H

#include <atlbase.h>
#include <d3d11.h>
#include <DirectXMath.h>
#include <dxgi.h>
using namespace DirectX;

#include <vector>
using namespace std;

#include "../Utility/TextureManager.h"

struct ScreenCBuffer
{
	XMFLOAT4 screenWidthHeight;
};

struct PlaneCBuffer
{
	XMFLOAT4 widthHeightLocation;
	XMFLOAT4 scaleRotationDepth;
};

struct SrcRectCBuffer
{
	XMFLOAT4 srcRect;
};

struct ColorCBuffer
{
	XMFLOAT4 color;
};

struct TexturesUsedCBuffer
{
	XMFLOAT4 texturesUsed;
};

struct LightInformation
{
	XMFLOAT4 lightPosition;
	XMFLOAT4 lightColor;
};

struct RenderCall
{
	int objectID;
	char texturesUsed;
	float posX;
	float posY;
	float scaleX;
	float scaleY;
	float rotation;
	RECT srcRect;
	float depth;
	XMFLOAT4 color;
};

class Sprite
{
public:
	Sprite();
	Sprite(const Sprite&);
	~Sprite();

	static void Initialize(int _screenWidth, int _screenHeight);
	static void AddRenderCall(int _objectID, char _texturesUsed, float _posX, float _posY, float _scaleX = 1.0f, float _scaleY = 1.0f, float _rotation = 0.0f, RECT _srcRect = RECT(), float _depth = 0.5f, XMFLOAT4 color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
	static void RenderFrame();
	static void Render(int _objectID, char _texturesUsed, float _posX, float _posY, float _scaleX = 1.0f, float _scaleY = 1.0f, float _rotation = 0.0f, RECT _srcRect = RECT(), float _depth = 0.5f, XMFLOAT4 color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));

	static int CompareDepth(const void* _first, const void* _second);
	//static bool Initialize();

	//FOR THE TEMPORARY LIGHT
	static LightInformation lightInformationCBuffer;

private:

	static vector<RenderCall> renderCalls;
	static CComPtr<ID3D11VertexShader> vertexShader;
	static CComPtr<ID3D11GeometryShader> geometryShader;
	static CComPtr<ID3D11PixelShader> pixelShader;

	static CComPtr<ID3D11SamplerState> samplerState;
	static CComPtr<ID3D11Buffer> vertexBuffer;
	static CComPtr<ID3D11InputLayout> inputLayout;

	static ScreenCBuffer screenCBuffer;
	static PlaneCBuffer planeCBuffer;
	static ColorCBuffer colorCBuffer;
	static TexturesUsedCBuffer texturesUsedCBuffer;
	static SrcRectCBuffer srcRectCBuffer;

	static CComPtr<ID3D11Buffer> screenGeometryCBuffer;
	static CComPtr<ID3D11Buffer> planeGeometryCBuffer;
	static CComPtr<ID3D11Buffer> srcRectGeometryCBuffer;
	static CComPtr<ID3D11Buffer> colorPixelCBuffer;
	static CComPtr<ID3D11Buffer> texturesUsedPixelCBuffer;
	static CComPtr<ID3D11Buffer> lightInformationPixelCBuffer;
};

#endif // !SPRITE_H
